package com.cx.service.impl;

import com.cx.mapper.CriticMapper;
import com.cx.pojo.Critic;
import com.cx.pojo.CriticExample;
import com.cx.service.CriticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CriticServiceImpl implements CriticService {

    @Autowired
    CriticMapper criticMapper;

    @Override
    public int insert(Critic critic) {
       int rows = criticMapper.insertSelective(critic);
       return rows;
    }

    @Override
    public int updateById(Integer criticId,Critic critic) {
        CriticExample criticExample = new CriticExample();
        CriticExample.Criteria criteria = criticExample.createCriteria();
        criteria.andCriticIdEqualTo(criticId);
        int rows = criticMapper.updateByExample(critic,criticExample);
        return rows;
    }

    @Override
    public int deleteById(Integer criticId) {
        CriticExample criticExample = new CriticExample();
        CriticExample.Criteria criteria = criticExample.createCriteria();
        criteria.andCriticIdEqualTo(criticId);
        int rows = criticMapper.deleteByExample(criticExample);
        return rows;
    }

    @Override
    public Critic selectById(Integer criticId) {
        CriticExample criticExample = new CriticExample();
        CriticExample.Criteria criteria = criticExample.createCriteria();
        criteria.andCriticIdEqualTo(criticId);
        Critic critic = criticMapper.selectByPrimaryKey(criticId);
        return critic;
    }

    @Override
    public List<Critic> selectByPostId(Integer psotId) {
        List<Critic> critics = criticMapper.selectByPostId(psotId);
        return critics;
    }

    @Override
    public List<Critic> selectByUserId(Integer userId) {
        List<Critic> critics = criticMapper.selectByUserId(userId);
        return critics;
    }

}
